<!DOCTYPE html>
<html class="index_body">
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=10">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <title></title>
    <link rel="stylesheet" href="/Public/mui/computer/css/bootstrap.css"/>
    <link rel="stylesheet" href="/Public/mui/computer/css/index.css"/>
    <link rel="stylesheet"  href="/Public/mui/static/bower_components/sweetalert/dist/sweetalert.css">
</head>
<body class="index_body">
<include file="Lay:heder" />
<div id="section" style="padding-top: 20px">
    <table class="table table-striped table-hover all_table">
        <thead class="all_thead">
        <tr>
            <th>库存所在地</th>
            <th>颜色</th>
            <th>库存数量</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>
                <div class="controls">
                    <select id="province">
                        <option value="">载入中</option>
                    </select>
                </div>
                <div class="controls" style="margin-left: 15px">
                    <select id="city">
                        <option value="">载入中</option>
                    </select>
                </div>
            </td>
            <td>
                <input type="text" id="colorid" style="border: 1px solid #ccc"/>
            </td>
            <td>
                <input type="number" id="sockid" style="border: 1px solid #ccc"/>
            </td>
            <td>
                <button type="button" onclick="test()" class="button buttlt">保存</button>
            </td>
        </tr>
        </tbody>
    </table>
    <include file="News:news" />
</div>
<script src="/Public/mui/computer/js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/Public/mui/static/bower_components/sweetalert/dist/sweetalert.min.js"></script>
<script src="/Public/Home/js/jquery.city.select.min.js"></script>
<script src="/Public/Home/js/data.js"></script>
<script src="/Public/Home/js/require.min.js"></script>
<script type="text/javascript" src="/Public/mui/computer/js/functions.js?v=asdf2"></script>
<script type="text/javascript" src="/Public/mui/computer/js/sotck.js"></script>
<script src="/Public/mui/computer/js/back.js"></script>
<script>
    $("#logo_type").attr("src","/Public/mui/computer/img/kucun.png");
    $(function () {
        // var provinceid  = $('#province').val();
        $('#province, #city').citylist({
            data: data,
            id: 'id',
            children: 'cities',
            name: 'name',
            metaTag: 'name'
        });
    });
    
    function test(){
        // var province = $("#province").attr('name');
        var provinceid = $("#province").find("option:selected").attr("name");
        var cityid     = $("#city").find("option:selected").attr("name");
        var provincename = $("#province").val();
        var cityname  = $("#city").val();
        var colorid = $("#colorid").val();
        var sockid = $("#sockid").val();
        var carnum = GetQueryString('carnum');
        if(province == ""){
            sweetAlert("","请选择省","error");
            return false;
        }
        if(city == ""){
            sweetAlert("","请选择市","error");
            return false;
        }
        
        if(colorid == ""){
            sweetAlert("","请填写颜色","error");
            return false;
        }
        if(sockid == ""){
            sweetAlert("","请填写库存","error");
            return false;
        }
        data = {provinceid:provinceid,cityid:cityid,provincename:provincename,cityname:cityname,sockid:sockid,carnum:carnum,color:colorid};
        post("/admin/Stock/addStock",data,function(res){
            console.log(res)
            if(res.success == "OK"){
                 sweetAlert("",res.msg,"success");
                 setTimeout(function () {
                  location.href = '/admin/Stock/cangku?carnum='+carnum;
                },2000);
            }else if(res.success == "ERROR"){
                sweetAlert("",res.msg,"error");
                setTimeout(function () {
                  location.href = '/admin/Stock/cangku?carnum='+carnum;
                },2000);
            }
        });
    }

    function GetQueryString(name)
    {
         var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
         var r = window.location.search.substr(1).match(reg);
         if(r!=null)return  unescape(r[2]); return null;
    }
</script>
</body>
</html>